package top.ytazwc.principle.singleresponsibility;

/**
 * 方案2
 * @author 花木凋零成兰
 * @date 2024/4/15 22:47
 */
public class SingleResponsibility2 {
    public static void main(String[] args) {
        RoadVehicle roadVehicle = new RoadVehicle();
        roadVehicle.run("摩托车");

        WaterVehicle waterVehicle = new WaterVehicle();
        roadVehicle.run("轮船");

        AirVehicle airVehicle = new AirVehicle();
        airVehicle.run("飞机");
    }
}
// 方案2分析
// 1. 遵守单一职责原则
// 2. 但是改动过大，即将类分解，同时也需要修改客户端
// 3. 改进：直接修改Vehicle类，改动的代码会比较少
class RoadVehicle {
    public void run(String vehicle) {
        System.out.println(vehicle + " 公路运行");
    }
}
class AirVehicle {
    public void run(String vehicle) {
        System.out.println(vehicle + " 天空运行");
    }
}
class WaterVehicle {
    public void run(String vehicle) {
        System.out.println(vehicle + " 水路运行");
    }
}